
$MOD51
	ORG	00H
MAIN:
lcall	kieu_1
lcall	kieu_2

ljmp main

; chuong trinh con
kieu_1:

	MOV	R0,#00H
	;TAT TAT CA CAC PORT
	mov 	p0,#00H 
	MOV	P1,#00H
	MOV	P2,#00H
	MOV 	P3,#00H
STAR1:
	
	MOV	DPTR,#DATADISP1 ;CSDL DIEU KHIEN CAC BIT
	MOV	A,R0
	MOVC	A,@A+DPTR
	MOV	P1,A ; PORT DUOC NAP DU LIEU VAO


	MOV	DPTR,#DATADISP3 ;CSDL DIEU KHIEN CAC BIT
	MOV	A,R0
	MOVC	A,@A+DPTR
	MOV	P3,A ; PORT DUOC NAP DU LIEU VAO

	
LCALL	DELAY1
	INC R0
	CJNE	R0,#96,star1 ;THAY DOI SO NAY THEO CSDL
	RET


kieu_2:

	MOV	R0,#00H
	;TAT TAT CA CAC PORT
	mov 	p0,#00H 
	MOV	P1,#00H
	MOV	P2,#00H
	MOV 	P3,#00H


STAR2:
      MOV	DPTR,#DATADISP3 ;CSDL DIEU KHIEN CAC BIT
	MOV	A,R0
	MOVC	A,@A+DPTR
	MOV	P0,A ; PORT DUOC NAP DU LIEU VAO

	
LCALL	DELAY2
	INC R0
	CJNE	R0,#8,star1 ;THAY DOI SO NAY THEO CSDL
	RET


;nhom lenh cac vong lap
DELAY1:
	PUSH	00H
	MOV	R0,#70
	MOV	TMOD,#01H
LOOP1:
	MOV	TH0,#HIGH(-3000);CHINH TOC DO
	MOV	TL0,#LOW(-3000);CHINH TOC DO
	SETB	TR0
 	JNB	TF0,$
	CLR	TR0
	CLR	TF0
	DJNZ	R0,LOOP1
	POP	00H
	RET


DELAY2:
	PUSH	00H
	MOV	R0,#70
	MOV	TMOD,#01H
LOOP2:
	MOV	TH0,#HIGH(-4000);CHINH TOC DO
	MOV	TL0,#LOW(-4000);CHINH TOC DO
	SETB	TR0
 	JNB	TF0,$
	CLR	TR0
	CLR	TF0
	DJNZ	R0,LOOP2
	POP	00H
	RET


DELAY3:
	PUSH	00H
	MOV	R0,#70
	MOV	TMOD,#01H
LOOP3:
	MOV	TH0,#HIGH(-3000);CHINH TOC DO
	MOV	TL0,#LOW(-3000);CHINH TOC DO
	SETB	TR0
 	JNB	TF0,$
	CLR	TR0
	CLR	TF0
	DJNZ	R0,LOOP2
	POP	00H
	RET


DELAY4:
	PUSH	00H
	MOV	R0,#70
	MOV	TMOD,#01H
LOOP4:
	MOV	TH0,#HIGH(-2000);CHINH TOC DO
	MOV	TL0,#LOW(-2000);CHINH TOC DO
	SETB	TR0
 	JNB	TF0,$
	CLR	TR0
	CLR	TF0
	DJNZ	R0,LOOP4
	POP	00H
	RET


DELAY5:
	PUSH	00H
	MOV	R0,#70
	MOV	TMOD,#01H
LOOP5:
	MOV	TH0,#HIGH(-1000);CHINH TOC DO
	MOV	TL0,#LOW(-1000);CHINH TOC DO
	SETB	TR0
 	JNB	TF0,$
	CLR	TR0
	CLR	TF0
	DJNZ	R0,LOOP5
	POP	00H
	RET


DELAY6:
	PUSH	00H
	MOV	R0,#70
	MOV	TMOD,#01H
LOOP6:
	MOV	TH0,#HIGH(-700);CHINH TOC DO
	MOV	TL0,#LOW(-700);CHINH TOC DO
	SETB	TR0
 	JNB	TF0,$
	CLR	TR0
	CLR	TF0
	DJNZ	R0,LOOP6
	POP	00H
	RET


DELAY7:
	PUSH	00H
	MOV	R0,#70
	MOV	TMOD,#01H
LOOP7:
	MOV	TH0,#HIGH(-300);CHINH TOC DO
	MOV	TL0,#LOW(-300);CHINH TOC DO
	SETB	TR0
 	JNB	TF0,$
	CLR	TR0
	CLR	TF0
	DJNZ	R0,LOOP7
	POP	00H
	RET


;-----------------------------------
;du lieu dung de dieu khien

DATADISP1:
DB	00000001B,00000010B,00000100B,00001000B,00010000B,00100000B,01000000B,10000000B,
DB	00000000B,00000000B,00000000B,00000000B,00000000B,00000000B,00000000B,00000000B,
DB	10000000B,01000000B,00100000B,00010000B,00001000B,00000100B,00000010B,00000001B,
DB	00000000B,00000000B,00000000B,00000000B,00000000B,00000000B,00000000B,00000000B
DB	11111111B,00000000B,11111111B,00000000B,11111111B,00000000B,11111111B,00000000B,
DB	11111111B,00000000B,11111111B,00000000B,11111111B,00000000B,11111111B,00000000B,
DB	11111111B,11111110B,11111100B,11111000B,11110000B,11100000B,11000000B,10000000B,
DB	00000000B,00000000B,00000000B,00000000B,00000000B,00000000B,00000000B,00000000B,


DATADISP3:
DB	00000000B,00000000B,00000000B,00000000B,00000000B,00000000B,00000000B,00000000B,
DB	00000001B,00000010B,00000100B,00001000B,00010000B,00100000B,01000000B,10000000B,
DB	00000000B,00000000B,00000000B,00000000B,00000000B,00000000B,00000000B,00000000B,
DB	10000000B,01000000B,00100000B,00010000B,00001000B,00000100B,00000010B,00000001B,
DB	11111111B,00000000B,11111111B,00000000B,11111111B,00000000B,11111111B,00000000B,
DB	11111111B,00000000B,11111111B,00000000B,11111111B,00000000B,11111111B,00000000B,
DB	11111111B,11111111B,11111111B,11111111B,11111111B,11111111B,11111111B,11111111B,
DB	11111110B,11111100B,11111000B,11110000B,11100000B,11000000B,10000000B,00000000B,

DATADISP2:
DB	11111111B,00000000B,11111111B,00000000B,11111111B,00000000B,11111111B,00000000B,

end


